package com.ecoolex.chinadutyfree.retailer.core.manager;

import com.ecoolex.chinadutyfree.retailer.core.dao.DirectMailGoodsOrderIncrementDataDAO;
import com.ecoolex.chinadutyfree.retailer.entity.DirectMailGoodsOrderIncrementData;
import com.ecoolex.chinadutyfree.retailer.enums.DirectMailGoodsOrderStatus;
import com.ecoolex.chinadutyfree.retailer.pojo.OrderStatisticsIncrementDTO;
import com.ecoolex.framework.common.util.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DirectMailGoodsOrderIncrementDataManager {
    @Autowired
    private DirectMailGoodsOrderIncrementDataDAO dao;
    
    /**
     * 订单数据每日增量统计，定时任务每天零点执行一次查询前一天的数据
     */
    public Long orderIncrementData(String updateUser,Date statisticsDate,Date recordTime) {
    	//获取目标统计日期的字符串
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    	String yesterday = format.format(statisticsDate);
    	
    	DateUtil.cleanTimePart(recordTime);
    	return dao.add(yesterday, yesterday, 
    		DirectMailGoodsOrderStatus.PAID.real(), 
    		DirectMailGoodsOrderStatus.COMPLETE.real(),
    		DirectMailGoodsOrderStatus.WAIT_RECECEIVE.real(),
    		DirectMailGoodsOrderStatus.AFTER_SALES.real(),
    		DirectMailGoodsOrderStatus.CLOSED.real(),
    		recordTime, updateUser,new Date(), 
    		updateUser,new Date(),DirectMailGoodsOrderIncrementData.NOT_DELETED);	
    }
    
    /**
     * 根据日期范围查询直邮订单增量总和
     * @param startDate
     * @param endDate
     * @return
     */
    public OrderStatisticsIncrementDTO getIncrementDataByDate(Date startDate,Date endDate) {
    	return dao.getIncrementDataByDate(startDate, endDate);
    }
    
    /**
     * 根据日期范围查询直邮订单增量列表
     * @param startDate
     * @param endDate
     * @return
     */
    public List<DirectMailGoodsOrderIncrementData> incrementDataList(Date startDate,Date endDate){
    	return dao.incrementDataList(startDate, endDate);
    }
}